package org.brisling.common.queryService;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.common.domain.CommonDomain;
import org.brisling.common.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * <p>Title: QueryCommonService</p>
 * <p>Description: 获取公共路径html文件</p>
 * <p>Company: tongking</p>
 * @author jackson wang
 * @since 1.0
 * @version 1.0
 * @date 2016年9月8日 下午8:10:19
 */
@RestController
@RequestMapping("/common/query")
public class QueryCommonService extends AbstractBaseQueryService<CommonDomain>{
	
	
	private static String commonSubsystem= "sysman";
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	/**
	 * 获取模块指定页面
	 * @param module	模块名称，为空取值“common”
	 * @param code		页面代码名称，为空取值“main”
	 * @return
	 */
	@RequestMapping("/getPage.action")
	public ModelAndView getPage(@RequestParam(value="module",required=false) String module,
			@RequestParam(value="code",required=false) String code){
		
		String _module = module==null?"common":module;
		String _code = code==null?"main":code;
		
			
			return new ModelAndView(String.format("/%1$s/%2$s", _module,_code));
		
	}
	
	/**
	 * 获取模块指定页面
	 * @param subSystem	子系统名称
	 * @param module	模块名称，为空取值“common”
	 * @param code		页面代码名称，为空取值“main”
	 * @return
	 */
	@RequestMapping("/getBizPage.action")
	public ModelAndView getBizPage(@RequestParam(value="subSystem",required=false) String subSystem,
			@RequestParam(value="module",required=false) String module,
			@RequestParam(value="code",required=false) String code){
		
		
		String _module = module==null?"common":module;
		String _code = code==null?"main":code;
		if(subSystem!=null){
			
			return new ModelAndView(String.format("/%1$s/%2$s/%3$s", subSystem,_module,_code));
		}else{
			return new ModelAndView(String.format("/%1$s/%2$s", _module,_code));
		}
		
	}
	
	@RequestMapping("/deptSelect.action")
	public ModelAndView getMainPage(){
		
		
		String moduName="deptSelect";
		String mp = String.format("/%1$s/%2$s/main", commonSubsystem,moduName);
		return new ModelAndView(mp);
		
	}
	
	@RequestMapping("/deptUserSelect.action")
	public ModelAndView getDeptUserPage(){
		
		String moduName="deptUserSelect";
		String mp = String.format("/%1$s/%2$s/main", commonSubsystem,moduName);
		return new ModelAndView(mp);
	}
	
	@RequestMapping("/deptPatientSelect.action")
	public ModelAndView getDeptPatientPage(){
		
		String moduName="deptPatientSelect";
		String mp = String.format("/%1$s/%2$s/main", commonSubsystem,moduName);
		return new ModelAndView(mp);
		
	}
	
	@RequestMapping("/deptOutpatientSelect.action")
	public ModelAndView getDeptOutpatientPage(){
		
		String moduName="deptOutpatientSelect";
		String mp = String.format("/%1$s/%2$s/main", commonSubsystem,moduName);
		return new ModelAndView(mp);
		
	}
	
	@RequestMapping("/supplySelect.action")
	public ModelAndView getSupplySelectPage(){		
		return new ModelAndView("/supply/supplySelect/main");
	}
	
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}
	
	@RequestMapping("/generatePage.action")
	public ModelAndView generatePage(@RequestBody(required=false) String body){
		return this.getBizEditPage();
	}
	
	@RequestMapping("/groupSelect.action")
	public ModelAndView getGroupPage(){
		
		String moduName="groupSelect";
		String mp = String.format("/%1$s/%2$s/main", commonSubsystem,moduName);
		return new ModelAndView(mp);
	}
	
	
}
